<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): ThinkPad
  - Date: 2018-05-25 09:30:16
  - Description:
-->
<head>
<title>Title</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="<%= request.getContextPath() %>/common/nui/nui.js" type="text/javascript"></script>
    
</head>
<body>
  
		<div>
		    <input class="nui-hidden" name="zhmyScheduleFile.sfAddress" id="ftAddress" />
		 	<table id="table1" class="table" style="height: 100%;width:100%;">
		 	     <tr>
				            	<td class="form_label">
                        上传文件:
                    </td>
                    <td colspan="1">
                    	<form id="fileForm" enctype="multipart/form-data" method="post">
     						<input type="file" name="file" id="file" style="width:calc(100% - 80px)"/> 
    						<input type="button" value="上传" onclick="upload()" />     
  						</form>
				      
				</tr>
				
				<tr>
				      <td>
				       文档名称:
				      </td>
				     <td colspan="1">
				     <input id="other" name="qitaren" value="" style="width:100%"/>
                          <!--<input class="nui-textbox" id="xxx" name="zhmyScheduleFile.sfName" required="true" vtype="maxLength:10" />-->
                    </td>
				
				</tr>
				
				<tr>
					<td class="form_label">版本选择:</td>
					<td colspan="1"><input id="lookup5"
						name="criteria/_expr[3]/zhmyVersionChange.vcId" class="nui-lookup"
						textField="vcVersionNumber" valueField="vcId" popupWidth="auto"
						popup="#gridPanel5" grid="#datagrid5" multiSelect="false" style="width:100%" />
						 <input  class="nui-hidden" name="criteria/_expr[3]/_op" value="=">
					</td>
				</tr>
				
			</table>		
		</div>
			
	      <div class="nui-toolbar" style="padding:0px;" borderStyle="border:0;">
                <table width="100%">
                    <tr>
                        <td style="text-align:center;" colspan="4">
                            <a class="nui-button" iconCls="icon-save" onclick="onOk()">
                                保存
                            </a>
                            <span style="display:inline-block;width:25px;">
                            </span>
                            <a class="nui-button" iconCls="icon-cancel" onclick="onCancel()">
                                取消
                            </a>
                        </td>
	
	
		<div id="gridPanel5" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>接收人:</span> <input id="keyText5" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick5" /> <a
					class="nui-button" onclick="onSearchClick5">查询</a> <a
					class="nui-button" onclick="onClearClick5">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick5">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid5" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="orgs"
			url="com.zhmy.xmgl.zhmyprojectmanage.getVersionListOfProject.biz.ext">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="vcVersionNumber" width="120" headerAlign="center"
					allowSort="true">版本名称</div>
			</div>
		</div>
	</div>   
	<script type="text/javascript">
	
		//从url路径获取projectid
    var globalprojectId = "<%=request.getParameter("projectId")%>";
    if (globalprojectId > 0 ) {
    } else {
		globalprojectId = 1;
    }
    
		nui.parse();
		
		var global_address;
    /*  
		$("#doSubmit").click(function() {
			if ($("#fileForm input[type='file']").val().length > 0) {
				$("#fileForm").submit();
			} else {
				nui.alert('请选择文件');
			}
		});
*/

  		//选择办班的操作代码
        var grid5 = nui.get("datagrid5");
		var keyText5 = nui.get("keyText5");
		//grid5.load();
		grid5.load({
				key : keyText5.value ,
				projectid: globalprojectId
			});
	 	function onSearchClick5(e) { 
			grid5.load({
				key : keyText5.value ,
				projectid: globalprojectId
			});
		}
			
		function onCloseClick5(e) {
			var lookup2 = nui.get("lookup5");
			lookup2.hidePopup(); 
		}
			
		function onClearClick5() {
			var lookup2 = nui.get("lookup5");
			lookup2.deselectAll();
		}
		    //异步文件上传
                    function upload() {
                    nui.alert("上传成功");
					    var formData = new FormData;
					    var fileData = $("#file");
						formData.append("myfile", fileData[0].files[0]);
					    var url = "<%=request.getContextPath()%>/xmgl/MangerSavefile.jsp";
					    formData.projectId = " ";
					    $.ajax({    
					        contentType:"multipart/form-data",  
					        url:url,    
					        type:"POST",
					        data:formData,  
					        dataType:"text",  
					        processData: false,  // 告诉jQuery不要去处理发送的数据  
					        contentType: false,   // 告诉jQuery不要去设置Content-Type请求头  
					        success: function(data){
					        	var strcookie = document.cookie;
					        	//alert(strcookie);
					        	var arrcookie  = strcookie.split("; ");
					        	//alert(arrcookie);
					        	for ( var i = 0; i < arrcookie.length; i++) {
									var arr = arrcookie[i].split("=");
									if (arr[0] == "address"){
										var address = $.trim(arr[1]);	
										address=decodeURIComponent(address,"utf-8");
										var reg = /^[\'\"]+|[\'\"]+$/g;
										address = address.replace(reg,"");
										global_address = address;
									}
								}
					        	
					        }  
					    });  
                    }
        function saveData() {
        
        		
			var version = nui.get("lookup5").getValue();
			//var filename2 = $("#other").val();//ok
			var filename = document.getElementById("other").value;//ok too
		
			
			var address = global_address;
			
            var sfid=<%=request.getParameter("sfid") %>;
            
            console.log(version);
            console.log(filename);
            console.log(address);
            console.log(sfid);
           
           
			//var json = "{'sfid':" + sfId+",'filename':'"+filename+"','fileaddress':'"+global_address+"','fileversionid':"+version+"}";
			//var json = "{'sfid':"+sfid+",'filename':"+filename+"',fileaddress':"+address+"',fileversionid':"+version+"}";
			
               var data =new Object();
               data.sfid=sfid;
               data.filename=filename;
               data.fileaddress=address;
               data.fileversionid=version;
               var json = nui.encode(data);
          
	        $.ajax({
	            url:"com.zhmy.xmgl.zhmyprojectmanage.saveUploadDoc.biz.ext",
	            type:'POST',
	            data:json,
	            cache:false,
	            contentType:'text/json',
	            success:function(text){
	                var returnJson = nui.decode(text);
	                if(returnJson.exception == null){

	                	 CloseWindow("saveSuccess");
	                	//CloseWindow(dd);
	                }else{
	                    nui.alert("saveData error", "系统提示", function(action){
	                        if(action == "ok" || action == "close"){
	                          
	                        }
	                    });
	                }
	            }
	   		 });
		}
                    
                         //关闭窗口
                    function CloseWindow(action) {
                        if (action == "close" && form.isChanged()) {
                            if (confirm("数据被修改了，是否先保存？")) {
                                saveData();
                            }
                        }
                        if (window.CloseOwnerWindow)
                        return window.CloseOwnerWindow(action);
                        else window.close();
                    }
                    
                        //确定保存或更新
                    function onOk() {
                        saveData();
                    }

                    //取消
                    function onCancel() {
                        CloseWindow("cancel");
                    }
    </script>
</body>
</html>